package com.xiaoyushu.oss.biz.factory;

import com.xiaoyushu.oss.biz.strategy.FileStragegy;
import com.xiaoyushu.oss.biz.strategy.impl.AliyunOSSFileStrategy;
import com.xiaoyushu.oss.biz.strategy.impl.MinioFileStrategy;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@RefreshScope
/**
 * 动态刷新配置，在配置中心 Nacos 的配置发送变更时，使用该注解可以让服务实列在不重启的情况下更新配置
 */
public class FileStrategyFactory {

    @Value("${storage.type}")
    private String strageType;

    @Bean
    @RefreshScope
    public FileStragegy getFileStrategy() {
        if (StringUtils.equals(strageType,"minio")){
            return new MinioFileStrategy();
        } else if (StringUtils.equals(strageType,"aliyun")) {
            return new AliyunOSSFileStrategy();

        }
        throw new IllegalArgumentException("不可用的存储类型");
    }


}
